package com.mb.mp.controller;

import com.mb.common.controller.BaseController;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import com.mb.common.utils.ShiroUtils;
import com.mb.mp.bo.MpCashDtlBO;
import com.mb.mp.domain.MpCashDtlDO;
import com.mb.mp.service.ICashService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 王源
 * @program mp-parent
 * @description 品牌库未完成
 * @date 2018-09-04 16:44
 **/
@Controller
@RequestMapping("/mp/cash")
public class CashController extends BaseController{
    private static final Logger logger = LoggerFactory.getLogger(CashController.class);

    @Autowired
    private ICashService cashService;

    @GetMapping("/index")
    String index(){
        return "/mp/cash_list";
    }


    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<MpCashDtlBO> list = cashService.queryList(query);
        int total = cashService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }

    @GetMapping("/toAudit/{id}")
    String toAudit(@PathVariable("id") Long id, Model model){
        MpCashDtlDO cashDtl = cashService.getCashDtl(id);
        model.addAttribute("cashDtl",cashDtl);
        return "/mp/cash_audit";
    }


    @ResponseBody
    @PostMapping("/audit")
    public R audit(MpCashDtlDO cashDtl) {
        cashDtl.setAuditor(new Integer(ShiroUtils.getUserId().intValue()));
        int result = cashService.audit(cashDtl);
        if(result != 0){
            return R.ok();
        }else{
            return R.error(1,"提现审核失败，请联系管理员");
        }
    }



}
